Random pick
am 15.12.2009 02:39:14 von David McGlone
Hi everyone,
I've been lurking in the shadows on the list for quite some time and now I'm
in need of a little info or advise.
I'm looking for a way to grab a record out of a database on a certain day each
month and I'm wondering if this can be accomplished with just a mysql query or
would I need to use PHP also?
My hunch is mixing the two, but I'm not very prolific with mysql at this point
so I thought It would be better to ask before I go and get myself all mixed
up.
Any suggestions?
--
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that
I had nowhere else to go.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 15.12.2009 03:02:37 von dmagick
David McGlone wrote:
> Hi everyone,
>
> I've been lurking in the shadows on the list for quite some time and now I'm
> in need of a little info or advise.
>
> I'm looking for a way to grab a record out of a database on a certain day each
> month and I'm wondering if this can be accomplished with just a mysql query or
> would I need to use PHP also?
A mysql query would do it but you'd use something to talk to mysql and
process the results (whether it's php, perl, python, ruby etc depends on
your other requirements).
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 15.12.2009 03:17:28 von David McGlone
On Monday 14 December 2009 21:02:37 Chris wrote:
> David McGlone wrote:
> > Hi everyone,
> >
> > I've been lurking in the shadows on the list for quite some time and now
> > I'm in need of a little info or advise.
> >
> > I'm looking for a way to grab a record out of a database on a certain day
> > each month and I'm wondering if this can be accomplished with just a
> > mysql query or would I need to use PHP also?
>
> A mysql query would do it but you'd use something to talk to mysql and
> process the results (whether it's php, perl, python, ruby etc depends on
> your other requirements).
>
What I'm trying to do is to have a record picked from the database at random
on the 1st of every month and display it on the page. Here is some code I have
been working with:
$query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
$result = @mysql_query($query);
if (!$result){
$query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
$result = @mysql_query($query);
while ($row = mysql_fetch_array($result)){
echo "$row[poochName] ";
echo "$row[Birthdate]";
}
}
I suspect this code isn't going to work, because I think on the 1st day of the
month it's going to choke.
What do you think?
--
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that
I had nowhere else to go.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 15.12.2009 03:43:44 von dmagick
David McGlone wrote:
> On Monday 14 December 2009 21:02:37 Chris wrote:
>> David McGlone wrote:
>>> Hi everyone,
>>>
>>> I've been lurking in the shadows on the list for quite some time and now
>>> I'm in need of a little info or advise.
>>>
>>> I'm looking for a way to grab a record out of a database on a certain day
>>> each month and I'm wondering if this can be accomplished with just a
>>> mysql query or would I need to use PHP also?
>> A mysql query would do it but you'd use something to talk to mysql and
>> process the results (whether it's php, perl, python, ruby etc depends on
>> your other requirements).
>>
>
> What I'm trying to do is to have a record picked from the database at random
> on the 1st of every month and display it on the page. Here is some code I have
> been working with:
>
> $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
> $result = @mysql_query($query);
> if (!$result){
>
> $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
> $result = @mysql_query($query);
>
> while ($row = mysql_fetch_array($result)){
> echo "$row[poochName] ";
> echo "$row[Birthdate]";
>
> }
> }
You can check the day of the month in php then do your other query:
$today = date('j');
if ($today !== 1) {
echo "Today isn't the first. No need to continue.\n";
exit;
}
...
random query etc here.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 15.12.2009 03:44:24 von dmagick
Chris wrote:
> David McGlone wrote:
>> On Monday 14 December 2009 21:02:37 Chris wrote:
>>> David McGlone wrote:
>>>> Hi everyone,
>>>>
>>>> I've been lurking in the shadows on the list for quite some time and
>>>> now
>>>> I'm in need of a little info or advise.
>>>>
>>>> I'm looking for a way to grab a record out of a database on a
>>>> certain day
>>>> each month and I'm wondering if this can be accomplished with just a
>>>> mysql query or would I need to use PHP also?
>>> A mysql query would do it but you'd use something to talk to mysql and
>>> process the results (whether it's php, perl, python, ruby etc depends on
>>> your other requirements).
>>>
>>
>> What I'm trying to do is to have a record picked from the database at
>> random on the 1st of every month and display it on the page. Here is
>> some code I have been working with:
>>
>> $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
>> $result = @mysql_query($query);
>> if (!$result){
>>
>> $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
>> $result = @mysql_query($query);
>>
>> while ($row = mysql_fetch_array($result)){
>> echo "$row[poochName] ";
>> echo "$row[Birthdate]";
>>
>> }
>> }
>
> You can check the day of the month in php then do your other query:
>
> $today = date('j');
See http://php.net/date for date formats and what they return.
> if ($today !== 1) {
> echo "Today isn't the first. No need to continue.\n";
> exit;
> }
> ..
> random query etc here.
>
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 16.12.2009 01:02:08 von David McGlone
On Monday 14 December 2009 21:44:24 Chris wrote:
> Chris wrote:
> > David McGlone wrote:
> >> On Monday 14 December 2009 21:02:37 Chris wrote:
> >>> David McGlone wrote:
> >>>> Hi everyone,
> >>>>
> >>>> I've been lurking in the shadows on the list for quite some time and
> >>>> now
> >>>> I'm in need of a little info or advise.
> >>>>
> >>>> I'm looking for a way to grab a record out of a database on a
> >>>> certain day
> >>>> each month and I'm wondering if this can be accomplished with just a
> >>>> mysql query or would I need to use PHP also?
> >>>
> >>> A mysql query would do it but you'd use something to talk to mysql and
> >>> process the results (whether it's php, perl, python, ruby etc depends
> >>> on your other requirements).
> >>
> >> What I'm trying to do is to have a record picked from the database at
> >> random on the 1st of every month and display it on the page. Here is
> >> some code I have been working with:
> >>
> >> $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
> >> $result = @mysql_query($query);
> >> if (!$result){
> >>
> >> $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
> >> $result = @mysql_query($query);
> >>
> >> while ($row = mysql_fetch_array($result)){
> >> echo "$row[poochName] ";
> >> echo "$row[Birthdate]";
> >>
> >> }
> >> }
> >
> > You can check the day of the month in php then do your other query:
> >
> > $today = date('j');
>
> See http://php.net/date for date formats and what they return.
>
> > if ($today !== 1) {
> > echo "Today isn't the first. No need to continue.\n";
> > exit;
> > }
> > ..
> > random query etc here.
>
Hmmm. This isn't exactly what I'm looking for. What I'm trying to do is get a
new picture on the 1st of every month and display it for that whole month.
--
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that
I had nowhere else to go.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 18.12.2009 17:10:10 von Philip Thompson
On Dec 15, 2009, at 6:02 PM, David McGlone wrote:
> On Monday 14 December 2009 21:44:24 Chris wrote:
>> Chris wrote:
>>> David McGlone wrote:
>>>> On Monday 14 December 2009 21:02:37 Chris wrote:
>>>>> David McGlone wrote:
>>>>>> Hi everyone,
>>>>>>=20
>>>>>> I've been lurking in the shadows on the list for quite some time =
and
>>>>>> now
>>>>>> I'm in need of a little info or advise.
>>>>>>=20
>>>>>> I'm looking for a way to grab a record out of a database on a
>>>>>> certain day
>>>>>> each month and I'm wondering if this can be accomplished with =
just a
>>>>>> mysql query or would I need to use PHP also?
>>>>>=20
>>>>> A mysql query would do it but you'd use something to talk to mysql =
and
>>>>> process the results (whether it's php, perl, python, ruby etc =
depends
>>>>> on your other requirements).
>>>>=20
>>>> What I'm trying to do is to have a record picked from the database =
at
>>>> random on the 1st of every month and display it on the page. Here =
is
>>>> some code I have been working with:
>>>>=20
>>>> $query =3D "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
>>>> $result =3D @mysql_query($query);
>>>> if (!$result){
>>>>=20
>>>> $query =3D "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
>>>> $result =3D @mysql_query($query);
>>>>=20
>>>> while ($row =3D mysql_fetch_array($result)){
>>>> echo "$row[poochName] ";
>>>> echo "$row[Birthdate]";
>>>>=20
>>>> }
>>>> }
>>>=20
>>> You can check the day of the month in php then do your other query:
>>>=20
>>> $today =3D date('j');
>>=20
>> See http://php.net/date for date formats and what they return.
>>=20
>>> if ($today !== 1) {
>>> echo "Today isn't the first. No need to continue.\n";
>>> exit;
>>> }
>>> ..
>>> random query etc here.
>>=20
>=20
> Hmmm. This isn't exactly what I'm looking for. What I'm trying to do =
is get a=20
> new picture on the 1st of every month and display it for that whole =
month.
Could you not just create a mysql table that contains the month and a =
url to a file?
// image.php
$currentMonth =3D date('n');
$sql =3D "SELECT `image_location` FROM `monthly_images` WHERE `month` =3D =
$currentMonth LIMIT 1";
$result =3D mysql_query($sql);
list ($loc) =3D mysql_result ($result);
header ("Content-type: image/png");
readfile ($loc);
exit;
?>
And then in your HTML:
I just wrote that code here in the email, but it should get you going in =
the right direction. Hope that helps!
~Philip=
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 19.12.2009 09:54:34 von Karl DeSaulniers
--Apple-Mail-2--562166622
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Dont know if you found anything, but I ran accross this in on of my
other searches.
http://php.about.com/od/finishedphp1/p/day_redirect.htm
Karl
On Dec 18, 2009, at 10:10 AM, Philip Thompson wrote:
> On Dec 15, 2009, at 6:02 PM, David McGlone wrote:
>
>> On Monday 14 December 2009 21:44:24 Chris wrote:
>>> Chris wrote:
>>>> David McGlone wrote:
>>>>> On Monday 14 December 2009 21:02:37 Chris wrote:
>>>>>> David McGlone wrote:
>>>>>>> Hi everyone,
>>>>>>>
>>>>>>> I've been lurking in the shadows on the list for quite some
>>>>>>> time and
>>>>>>> now
>>>>>>> I'm in need of a little info or advise.
>>>>>>>
>>>>>>> I'm looking for a way to grab a record out of a database on a
>>>>>>> certain day
>>>>>>> each month and I'm wondering if this can be accomplished with
>>>>>>> just a
>>>>>>> mysql query or would I need to use PHP also?
>>>>>>
>>>>>> A mysql query would do it but you'd use something to talk to
>>>>>> mysql and
>>>>>> process the results (whether it's php, perl, python, ruby etc
>>>>>> depends
>>>>>> on your other requirements).
>>>>>
>>>>> What I'm trying to do is to have a record picked from the
>>>>> database at
>>>>> random on the 1st of every month and display it on the page.
>>>>> Here is
>>>>> some code I have been working with:
>>>>>
>>>>> $query = "SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)";
>>>>> $result = @mysql_query($query);
>>>>> if (!$result){
>>>>>
>>>>> $query = "SELECT * FROM monthlyPooch ORDER BY RAND() LIMIT 1";
>>>>> $result = @mysql_query($query);
>>>>>
>>>>> while ($row = mysql_fetch_array($result)){
>>>>> echo "$row[poochName] ";
>>>>> echo "$row[Birthdate]";
>>>>>
>>>>> }
>>>>> }
>>>>
>>>> You can check the day of the month in php then do your other query:
>>>>
>>>> $today = date('j');
>>>
>>> See http://php.net/date for date formats and what they return.
>>>
>>>> if ($today !== 1) {
>>>> echo "Today isn't the first. No need to continue.\n";
>>>> exit;
>>>> }
>>>> ..
>>>> random query etc here.
>>>
>>
>> Hmmm. This isn't exactly what I'm looking for. What I'm trying to
>> do is get a
>> new picture on the 1st of every month and display it for that
>> whole month.
>
> Could you not just create a mysql table that contains the month and
> a url to a file?
>
>
> // image.php
> $currentMonth = date('n');
> $sql = "SELECT `image_location` FROM `monthly_images` WHERE `month`
> = $currentMonth LIMIT 1";
> $result = mysql_query($sql);
> list ($loc) = mysql_result ($result);
>
> header ("Content-type: image/png");
> readfile ($loc);
> exit;
> ?>
>
> And then in your HTML:
>
>
>
> I just wrote that code here in the email, but it should get you
> going in the right direction. Hope that helps!
>
> ~Philip
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-2--562166622--
Re: Random pick
am 21.12.2009 13:49:52 von David McGlone
On Saturday 19 December 2009 03:54:34 Karl DeSaulniers wrote:
> Dont know if you found anything, but I ran accross this in on of my
> other searches.
>
> http://php.about.com/od/finishedphp1/p/day_redirect.htm
>
> Karl
>
> On Dec 18, 2009, at 10:10 AM, Philip Thompson wrote:
> > On Dec 15, 2009, at 6:02 PM, David McGlone wrote:
> >> On Monday 14 December 2009 21:44:24 Chris wrote:
> >>> Chris wrote:
> >>>> David McGlone wrote:
> >>>>> On Monday 14 December 2009 21:02:37 Chris wrote:
> >>>>>> David McGlone wrote:
> >>>>>>> Hi everyone,
> >>>>>>>
> >>>>>>> I've been lurking in the shadows on the list for quite some
> >>>>>>> time and
> >>>>>>> now
> >>>>>>> I'm in need of a little info or advise.
Thanks everyone. I tried everybody's suggestions and I learned a lot. Someone
else also suggested using a cron job to run the rand script at certain
intervals and insert the result into another table. This also works.
I probably could've used javascript, which was my initial reaction, but I'm
trying to learn PHP/MYSQL and adding java to the mix, would only add to the
confusion.
--
Blessings
David M.
I have been driven to my knees many times by the overwhelming conviction that
I had nowhere else to go.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 25.01.2010 20:13:17 von Karl DeSaulniers
--Apple-Mail-10-524272766
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Hello List,
Trying to learn the right way to code this line.
Can anyone tell me if I am doing this the right way?
if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||
9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||
"Employee" || "Sales" || "Investor" || "Human Resources" ||
"Administrator";
I am wanting to stray from the if(foo == bar) { routine. ;)
Thanks,
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-10-524272766--
Re: Random pick
am 25.01.2010 20:31:07 von olavi
Hi,
did you mean something like this?
$level_names = array("Guest", "Regular User", "Intl. User",
"Contractor", "Employee",
"Sales", "Investor", "Human Resources", "Administrator");
$user_level = $level_names[$req_user_level];
Regards,
Olavi Ivask
On Jan 25, 2010, at 9:13 PM, Karl DeSaulniers wrote:
> Hello List,
> Trying to learn the right way to code this line.
> Can anyone tell me if I am doing this the right way?
>
> if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||
> 9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||
> "Employee" || "Sales" || "Investor" || "Human Resources" ||
> "Administrator";
>
> I am wanting to stray from the if(foo == bar) { routine. ;)
>
> Thanks,
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 25.01.2010 20:32:27 von Peter Beckman
On Mon, 25 Jan 2010, Karl DeSaulniers wrote:
> Hello List,
> Trying to learn the right way to code this line.
> Can anyone tell me if I am doing this the right way?
>
> if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 ?
> "Guest" || "Regular User" || "Intl. User" || "Contractor" || "Employee" ||
> "Sales" || "Investor" || "Human Resources" || "Administrator";
>
> I am wanting to stray from the if(foo == bar) { routine. ;)
if (in_array($req_user_level, array(0,1,2,3,4,5,6,7,8,9,"Guest",...))) {
// do stuff
}
------------------------------------------------------------ ---------------
Peter Beckman Internet Guy
beckman@angryox.com http://www.angryox.com/
------------------------------------------------------------ ---------------
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 25.01.2010 20:39:24 von Karl DeSaulniers
--Apple-Mail-12-525839917
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Hi,
$req_user_level is a MySql return result and I am trying to utilize
shortened code to evaluate whither $req_user_level == 0 || 1 || 2 ||
3 || 4 || 5 || 6 || 7 || 8 || 9, if it matches a number, return the
text associated with that number.
"Guest" || "Regular User" || "Intl. User" || "Contractor" ||
"Employee" || "Sales" || "Investor" || "Human Resources" ||
"Administrator";
Karl
On Jan 25, 2010, at 1:31 PM, Olavi Ivask wrote:
> Hi,
>
> did you mean something like this?
>
> $level_names = array("Guest", "Regular User", "Intl. User",
> "Contractor", "Employee",
> "Sales", "Investor", "Human Resources", "Administrator");
>
> $user_level = $level_names[$req_user_level];
>
> Regards,
> Olavi Ivask
>
>
> On Jan 25, 2010, at 9:13 PM, Karl DeSaulniers wrote:
>
>> Hello List,
>> Trying to learn the right way to code this line.
>> Can anyone tell me if I am doing this the right way?
>>
>> if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||
>> 9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||
>> "Employee" || "Sales" || "Investor" || "Human Resources" ||
>> "Administrator";
>>
>> I am wanting to stray from the if(foo == bar) { routine. ;)
>>
>> Thanks,
>>
>> Karl DeSaulniers
>> Design Drumm
>> http://designdrumm.com
>>
>
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-12-525839917--
Re: Random pick
am 25.01.2010 20:42:23 von Karl DeSaulniers
--Apple-Mail-13-526018339
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
I am trying to avoid doing this:
if ($req_user_level == 0) {
$req_user_level = "Guest";
} else if ($req_user_level == 1) {
req_user_level = "Regular User"
}
etc..
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-13-526018339--
Re: Random pick
am 25.01.2010 20:44:59 von olavi
Don't you like my solution?
Regards,
Olavi
On Jan 25, 2010, at 9:39 PM, Karl DeSaulniers wrote:
> Hi,
> $req_user_level is a MySql return result and I am trying to utilize
> shortened code to evaluate whither $req_user_level == 0 || 1 || 2 ||
> 3 || 4 || 5 || 6 || 7 || 8 || 9, if it matches a number, return the
> text associated with that number.
> "Guest" || "Regular User" || "Intl. User" || "Contractor" ||
> "Employee" || "Sales" || "Investor" || "Human Resources" ||
> "Administrator";
>
> Karl
>
>
> On Jan 25, 2010, at 1:31 PM, Olavi Ivask wrote:
>
>> Hi,
>>
>> did you mean something like this?
>>
>> $level_names = array("Guest", "Regular User", "Intl. User",
>> "Contractor", "Employee",
>> "Sales", "Investor", "Human Resources", "Administrator");
>>
>> $user_level = $level_names[$req_user_level];
>>
>> Regards,
>> Olavi Ivask
>>
>>
>> On Jan 25, 2010, at 9:13 PM, Karl DeSaulniers wrote:
>>
>>> Hello List,
>>> Trying to learn the right way to code this line.
>>> Can anyone tell me if I am doing this the right way?
>>>
>>> if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||
>>> 9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||
>>> "Employee" || "Sales" || "Investor" || "Human Resources" ||
>>> "Administrator";
>>>
>>> I am wanting to stray from the if(foo == bar) { routine. ;)
>>>
>>> Thanks,
>>>
>>> Karl DeSaulniers
>>> Design Drumm
>>> http://designdrumm.com
>>>
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 25.01.2010 20:58:56 von Karl DeSaulniers
--Apple-Mail-17-527011082
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Thank you for this as well.
Question? What part is "in_array" playing?
Is it comparing $req_user_level to array()?
Because the text "Guest", etc.. is not in $req_user_level on the
database.
In other words, is it checking the value of $req_user_level to see if
"Guest" is in it?
Karl
On Jan 25, 2010, at 1:32 PM, Peter Beckman wrote:
> On Mon, 25 Jan 2010, Karl DeSaulniers wrote:
>
>> Hello List,
>> Trying to learn the right way to code this line.
>> Can anyone tell me if I am doing this the right way?
>>
>> if $req_user_level == 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 ||
>> 9 ? "Guest" || "Regular User" || "Intl. User" || "Contractor" ||
>> "Employee" || "Sales" || "Investor" || "Human Resources" ||
>> "Administrator";
>>
>> I am wanting to stray from the if(foo == bar) { routine. ;)
>
> if (in_array($req_user_level, array
> (0,1,2,3,4,5,6,7,8,9,"Guest",...))) {
> // do stuff
> }
>
> ------------------------------------------------------------ ----------
> -----
> Peter Beckman
> Internet Guy
> beckman@angryox.com http://
> www.angryox.com/
> ------------------------------------------------------------ ----------
> -----
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-17-527011082--
Re: Random pick
am 25.01.2010 21:24:23 von Peter Beckman
On Mon, 25 Jan 2010, Karl DeSaulniers wrote:
> Thank you for this as well.
> Question? What part is "in_array" playing?
> Is it comparing $req_user_level to array()?
> Because the text "Guest", etc.. is not in $req_user_level on the database.
> In other words, is it checking the value of $req_user_level to see if "Guest"
> is in it?
Sorry, I missed the question mark. in_array isn't appropriate here. The
previous poster has it right, assuming $req_user_level is an integer of
0..9.
$levels = array("Guest", "Regular User", 'Intl. User', ...)
// the array is 0 , 1 , 2 , ...)
Going a little further:
if (!empty($levels[$req_user_level])) { // is both set and doesn't evaluate to false
echo "The user is a {$levels[$req_user_level]}.\n";
} else {
// The $req_user_level was not a valid level.
echo "The returned req_user_level was not valid.\n";
}
Which would output, if $req_user_level was 1 (one):
The user is a Regular User.
Then you know you have a valid user level. Careful though -- sometimes 0
will be returned on a failure, depending on your SQL.
Beckman
------------------------------------------------------------ ---------------
Peter Beckman Internet Guy
beckman@angryox.com http://www.angryox.com/
------------------------------------------------------------ ---------------
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Random pick
am 25.01.2010 21:33:44 von Karl DeSaulniers
--Apple-Mail-19-529099053
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
Yes, $req_user_level is an int between 0 and 9.
Yes, the other code worked great.
Thank you for your response though.
That is definitely a good way to cross check.
Thanks again for your responses.
Best,
Karl
On Jan 25, 2010, at 2:24 PM, Peter Beckman wrote:
> On Mon, 25 Jan 2010, Karl DeSaulniers wrote:
>
>> Thank you for this as well.
>> Question? What part is "in_array" playing?
>> Is it comparing $req_user_level to array()?
>> Because the text "Guest", etc.. is not in $req_user_level on the
>> database.
>> In other words, is it checking the value of $req_user_level to see
>> if "Guest" is in it?
>
> Sorry, I missed the question mark. in_array isn't appropriate
> here. The
> previous poster has it right, assuming $req_user_level is an
> integer of
> 0..9.
>
> $levels = array("Guest", "Regular User", 'Intl. User', ...)
> // the array is 0 , 1 , 2 , ...)
>
> Going a little further:
>
> if (!empty($levels[$req_user_level])) { // is both set and
> doesn't evaluate to false
> echo "The user is a {$levels[$req_user_level]}.\n";
> } else {
> // The $req_user_level was not a valid level.
> echo "The returned req_user_level was not valid.\n";
> }
>
> Which would output, if $req_user_level was 1 (one):
>
> The user is a Regular User.
>
> Then you know you have a valid user level. Careful though --
> sometimes 0
> will be returned on a failure, depending on your SQL.
>
> Beckman
> ------------------------------------------------------------ ----------
> -----
> Peter Beckman
> Internet Guy
> beckman@angryox.com http://
> www.angryox.com/
> ------------------------------------------------------------ ----------
> -----
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Karl DeSaulniers
Design Drumm
http://designdrumm.com
--Apple-Mail-19-529099053--